#!/bin/bash
# usage:
#	cpath.sh <file_path> <Keywords> <Values>
show_help () {
	echo ""
	echo "cpath.sh [-h|-t] <file_path> <keyword> <value>"
	echo ""
}


main_core () {
	FilePath="$1"
	Heading="$2"
	Newline="$Heading = \'${3}\';"
	sed -i "/^${Heading}/c ${Newline}" "$FilePath"
	sed -n "/^${Heading}/p" "$FilePath"
}

main_noquat () {
	FilePath="$2"
	Heading="$3"
	Newline="$Heading = ${4};"
	sed -i "/^${Heading}/c ${Newline}" "$FilePath"
	sed -n "/^${Heading}/p" "$FilePath"
}

main_test () {
	FilePath="$2"
	Heading="$3"
	case "$1" in
		-tn|-nt ) Newline="$Heading = ${4};" ;;
		* ) Newline="$Heading = \'${4}\';" ;;
	esac
	sed -n "/^${Heading}/c ${Newline}" "$FilePath"
}

case "$1" in
	-h ) show_help ;;
	-t|-nt|-tn ) main_test "$1" "$2" "$3" "$4";;
	-n ) main_noquat "$1" "$2" "$3" "$4";;
	* ) main_core "$1" "$2" "$3" "$4";;
esac


